package com.beiding.my.common;

import java.lang.reflect.Method;

class BoVoBe {
    static Class getBeTypeFromBoType(Class<? extends Bo> bo) {
        Class type = (Class) Cache.get("BoVoBe.getBeTypeFromBoType", bo);
        if (type == null) {
            synchronized (BoVoBe.class) {
                if ((type = (Class) Cache.get("BoVoBe.getBeTypeFromBoType", bo)) == null) {
                    try {
                        type = getBeTypeFromVoType(getVoTypeFromBoType(bo));
                        Cache.put(type, "BoVoBe.getBeTypeFromBoType", bo);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return type;
    }

    //从bo中解析出vo中类型
    static Class<? extends Vo> getVoTypeFromBoType(Class<? extends Bo> bo) {
        Class<? extends Vo> type = (Class<? extends Vo>) Cache.get("BoVoBe.getVoTypeFromBoType", bo);
        if (type == null) {
            synchronized (BoVoBe.class) {
                if ((type = (Class<? extends Vo>) Cache.get("BoVoBe.getVoTypeFromBoType", bo)) == null) {
                    try {
                        Method getVo = bo.getMethod("getVo");
                        type = (Class<? extends Vo>) getVo.getReturnType();
                        Cache.put(type, "BoVoBe.getVoTypeFromBoType", bo);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return type;
    }

    //从vo中解析出vo类型
    static Class getBeTypeFromVoType(Class<? extends Vo> vo) {
        Class type = (Class) Cache.get("BoVoBe.getBeTypeFromVoType", vo);
        if (type == null) {
            synchronized (BoVoBe.class) {
                if ((type = (Class) Cache.get("BoVoBe.getBeTypeFromVoType", vo)) == null) {
                    try {
                        Method getBe = vo.getMethod("getBe");
                        type = getBe.getReturnType();
                        Cache.put(type, "BoVoBe.getBeTypeFromVoType", vo);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return type;
    }


}
